package com.yc.snack.biz.impl;

import com.yc.snack.biz.ITypeInfoBiz;
import com.yc.snack.dao.ITypeInfoDao;
import com.yc.snack.dao.impl.TypeInfoDaoImpl;
import com.yc.snack.entity.TypeInfo;
import com.yc.snack.util.StringUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: HuYang
 * @Date: 2022/11/10 - 11 - 10 - 20:17
 * @Description: com.yc.snack.biz.impl
 * @version: 1.0
 */
public class TypeInfoBizImpl implements ITypeInfoBiz {
    @Override
    public int add(TypeInfo tf) {
        if (StringUtil.checkNull(tf.getTname())){
            return -1;
        }
        ITypeInfoDao typeInfoDao = new TypeInfoDaoImpl();
        return typeInfoDao.add(tf);
    }

    @Override
    public List<TypeInfo> finds() {
        ITypeInfoDao typeInfoDao = new TypeInfoDaoImpl();

        return typeInfoDao.finds();
    }

    @Override
    public Map<String, Object> findByPage(int page, int rows) {
        ITypeInfoDao typeInfoDao = new TypeInfoDaoImpl();
        List<TypeInfo> list = typeInfoDao.findByPage(page,rows);
        Map<String,Object> result = new HashMap<>();
        if (list == null || list.isEmpty()){
            result.put("code","600");
            result.put("msg","暂无数据...");
            return result;
        }
        result.put("code",0);
        result.put("data",list);
        result.put("count",typeInfoDao.getTotal());
        return result;
    }
}
